﻿using System.Collections.Generic;
using DevExpress.Web.ASPxCallback;
using DevExpress.Web.ASPxEditors;
using Kaysite.Controller;
using Kaysite.Manager;
using Kaysite.Model;

public partial class Controls_AdminControls_ServiceEdit : BaseEditControl<ServiceManager, ServiceController, Service>
{
    protected override ASPxCallback GetCallbackControl()
    {
        return clbkSave;
    }

    protected override ASPxButton GetCancelButton()
    {
        return btnCancel;
    }

    protected override ASPxButton GetOkButton()
    {
        return btnOk;
    }

    protected override string BackUrl
    {
        get
        {
            return string.Format("{0}?view=ServiceList", Request.Path);
        }
    }

    protected override void DoInitialize_2_LoadDataInitControls()
    {
        base.DoInitialize_2_LoadDataInitControls();
        InitCombo<ServiceGroupManager>(ddlServiceGroup);
        InitComboEnum(ddlDisplayOption, e0Type.DontNeed,
            new List<eDisplayOption> { eDisplayOption.DisplayWithChild });
    }

    protected override void InitControlsByModelData(Service model)
    {
        if (model == null)
        {
            ddlDisplayOption.Value = (int)eDisplayOption.Hide;
            if (GetRequestParam<int>("ServiceGroupID") != 0)
                ddlServiceGroup.Value = GetRequestParam<int>("ServiceGroupID");
            return;
        }
        txtName.Text = model.Name;
        ddlServiceGroup.Value = model.ServiceGroupID;
        txtDescription.Html = model.Description;
        ddlDisplayOption.Value = (int)model.DisplyInMain;
    }

    protected override void LoadModelDataFromControls(Service model)
    {
        model.ServiceName = GetValue<string>(txtName);
        model.ServiceGroupID = GetValue<int>(ddlServiceGroup);
        model.Description = txtDescription.Html;
        model.DisplyInMain = GetValue<eDisplayOption>(ddlDisplayOption);
    }
}